import java.io.Serializable;
import java.util.ArrayList;

/**
 * 
 * This class handles help operations for the UI
 * 
 * @author Interactive Syllabus
 * 
 */
public class HelpHandler implements Serializable
{

    private static final long serialVersionUID = -7313720157572845648L;
    private ArrayList<HelpTopic> topicList = new ArrayList<HelpTopic>();

    /**
     * HelpHandler is the constructor for a HelpHandler class
     */
    public HelpHandler()
    {    }

    public HelpHandler(ArrayList<HelpTopic> topicArray)
    {
	this.topicList = topicArray;
    }

    /**
     * getHelp handles the search query for a help query.
     * 
     * @param searchTerm
     * @return HelpTopic searched for
     */
    public ArrayList<HelpTopic> getHelp(String searchTerm)
    {
	ArrayList<HelpTopic> results = new ArrayList<HelpTopic>();
	for (HelpTopic ht : this.topicList)
	{
	    if (ht.contains(searchTerm))
		results.add(ht);
	}
	return results;
    }

    /**
     * generateHelpTopic handles when the Instructor version adds help to the
     * UI.
     * 
     * @param topicName
     * @param topicBody
     */
    public void generateHelpTopic(String topicName, String topicBody)
    {
	this.topicList.add(new HelpTopic(topicName, topicBody));
    }

    public ArrayList<HelpTopic> getTopicList()
    {
	return this.topicList;
    }

}
